package view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;

import model.ExempleFigure;


import controller.ExempleModelController;

public class ZoneExemple extends JPanel{
	
	private ExempleModelController exempleModelController;
	private JComboBox listeModel;
	private JPanel imageExemplePanel;
	
	// Les modeles de figures
	ExempleFigure carre = new ExempleFigure("carré", "/images/carre.JPG");
	ExempleFigure escalier = new ExempleFigure("escalier", "/images/escalier.JPG");
	ExempleFigure triangle = new ExempleFigure("triangle", "/images/triangle.jpg");
	ExempleFigure lettreA = new ExempleFigure("lettreA", "/images/a.jpg");
	ExempleFigure lettreM = new ExempleFigure("lettreM", "/images/m.jpg");
	ImageIcon modele = new ImageIcon(getClass().getResource("/images/carre.JPG"));

	JLabel img;
	
	
	public ZoneExemple(ExempleModelController exempleModelController){
		this.exempleModelController = exempleModelController;
		this.setBorder(BorderFactory.createTitledBorder("Exemple de figure"));
		imageExemplePanel = new JPanel();
		imageExemplePanel.setPreferredSize(new Dimension(195 , 160));
		imageExemplePanel.setBackground(Color.white);
		
		listeModel = new JComboBox();
		
		listeModel.addItem("Carré");
		listeModel.addItem("Escalier");
		listeModel.addItem("Lettre A");
		listeModel.addItem("Lettre M");
		listeModel.addItem("Triangle");
		
		
		ActionListener chooseModel = new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e) {
				if(listeModel.getSelectedItem().equals("Carré")){
					ExempleModelController.doAfficherModel(carre);
				}
				if(listeModel.getSelectedItem().equals("Escalier")){
					ExempleModelController.doAfficherModel(escalier);
				}
				
				if(listeModel.getSelectedItem().equals("Triangle")){
					ExempleModelController.doAfficherModel(triangle);
				}
				if(listeModel.getSelectedItem().equals("Lettre A")){
					ExempleModelController.doAfficherModel(lettreA);
				}
				if(listeModel.getSelectedItem().equals("Lettre M")){
					ExempleModelController.doAfficherModel(lettreM);
				}
			}
			
		};
		
		listeModel.addActionListener(chooseModel);
		
		img = new JLabel(modele);
		imageExemplePanel.add(img);
        this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

		this.add(listeModel);
		this.add(imageExemplePanel);
		
	}
	
	public JLabel getImg() {
		return img;
	}

	public void setImg(JLabel img) {
		this.img = img;
	}
	
	public ImageIcon getModele() {
		return modele;
	}
	public void setModele(ImageIcon modele) {
		this.modele = modele;
	}
	
	
	
	
}
